//
//  JsKeyChainItem.m
//  JsUtilitySdk
//
//  Created by Gikki Ares on 2023/4/26.
//

#import "JsKeyChainItemA.h"

@implementation JsKeyChainItemA

- (instancetype)initWithString:(NSString *)string servie:(NSString *)service accessGroup:(NSString *)accessGroup {
	NSData * data = [string dataUsingEncoding:NSUTF8StringEncoding];
	return [self initWithData:data servie:service accessGroup:accessGroup];
}

- (instancetype)initWithData:(NSData *)data servie:(NSString *)service accessGroup:( NSString * __nullable)accessGroup {
	if(self == [super init]) {
		self.data = data;
		self.service = service;
		self.accessGroup = accessGroup;
	}
	return self;
}
- (instancetype)initWithDictionary:(NSDictionary *)dic {
	if(self == [super init]) {
		self.data = dic[(NSString *)kSecValueData];
		self.service = dic[(NSString *)kSecAttrService];
		self.accessGroup = dic[(NSString *)kSecAttrAccessGroup];
	}
	return self;
}

- (void)setData:(NSData *)data {
	_data = data;
	NSString * value = [[NSString alloc]initWithData:_data encoding:NSUTF8StringEncoding];
}

- (void)setStringData:(NSString *)string {
	NSData * data = [string dataUsingEncoding:NSUTF8StringEncoding];
	_data = data;
}
- (NSString *)stringData {
	NSString * str = [[NSString alloc] initWithData:_data encoding:NSUTF8StringEncoding];
	return str;
}

- (NSString *)toString {
	NSString * str = [NSString stringWithFormat:@"Value is: %@\nAccess Group is: %@\nService is: %@",[self stringData],self.accessGroup,self.service];
	return str;
}

@end
